#!/bin/sh -e
# Script to dispatch NetworkManager events(launch nac_client)
#

IF=$1
STATUS=$2

# Run the right scripts
if [ "$STATUS" = "up" ]; then
	if [ "x$DHCP4_DOMAIN_SEARCH" = "x" ]; then
		/usr/local/bin/join_ndn -a $DHCP4_IP_ADDRESS -p 9695 -s "$DHCP4_NAC_SERVER" -g "$DHCP4_NDN_GATEWAYS" -n "$DHCP4_NDN_NAMESPACE" -d "$DHCP4_DOMAIN_NAME" -f /opt/nac/join_ndn.conf 1>/dev/null 2>&1
	else
		/usr/local/bin/join_ndn -a $DHCP4_IP_ADDRESS -p 9695 -s "$DHCP4_NAC_SERVER" -g "$DHCP4_NDN_GATEWAYS" -n "$DHCP4_NDN_NAMESPACE" -d "$DHCP4_DOMAIN_SEARCH" -f /opt/nac/join_ndn.conf 1>/dev/null 2>&1
	fi
fi

if [ "$STATUS" = "down" ];then
	/usr/local/bin/ccndstop &
fi
